<template>
	<view>
		<u-upload @on-success="onsuccess" :file-list="fileList" :action="action" @on-error="onerror" :headers="headers"
			:max-size="5 * 1024 * 1024" max-count="1"></u-upload>
	</view>
</template>

<script>
	const commonHost = `http://www.union.yhdengdeng.net/api/upload/local`
	export default {
		props: ['path'],
		data() {
			return {
				fileList: []
			}
		},
		computed: {
			action() {
				return commonHost
			},
			headers() {
				return {
					Authorization: `Bearer ${uni.getStorageSync('token')}`,
				}
			}
		},
		created() {
			if (this.path!==undefined) {
				this.fileList.push({
					url: this.path,
				})
			}
		},
		methods: {
			onsuccess(data, index, lists, name) {
				console.log(data.path)
				this.updateImg(data.path)
			},
			onerror(res, index, lists, name) {
				console.log(res, index, lists, name)
			},
			updateImg(path) {
				this.$emit('update', path)
			},
			submit() {
				this.$refs.uUpload.upload();
			}
		}
	}
</script>

<style>

</style>
